<template>
  <div :id="id" class="echart-container" :style="{ width: width + 'px', height: height + 'px' }" />
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'Echart',
  props: {
    id: {
      type: String,
      default: ''
    },
    options: {
      type: Object,
      default: null
    },
    width: {
      type: Number,
      default: 500
    },
    height: {
      type: Number,
      default: 500
    }
  },
  data() {
    return {
      myChart: null
    }
  },
  watch: {
    options: {
      handler(val, oldVal) {
        this.myChart.setOption(val)
      },
      deep: true
    }
  },
  mounted() {
    const { id, options } = this
    this.myChart = echarts.init(document.getElementById(id))
    this.myChart.setOption(options || {})
  }
}
</script>

<style lang="less" scoped>
</style>
